﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ZLDC.Topo.BLL.Estate
{
   public  class lp_Configuration_below
    {
       public static void GetTb(string type, string name, Repeater RpList, string u_id, string daytime, Panel Panel2, Panel Panel1, System.Web.UI.HtmlControls.HtmlInputText txtallnum2, Repeater Repeater1, bool exists, System.Web.UI.HtmlControls.HtmlInputText txtallnum1)
       {
           if (name != "0")
           {

               Panel2.Visible = true;
               Panel1.Visible = false;

               DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Package where   Other3='" + name + "'  order by Other1  ");
               if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
               {
                   RpList.DataSource = ds.Tables[0];
                   RpList.DataBind();
               }
                              int total = 0;


               foreach (RepeaterItem Item in RpList.Items)
               {
                   CheckBox chk = (CheckBox)Item.FindControl("ckb");
                   TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");                   TextBox txtSinglePoint = (TextBox)Item.FindControl("txtSinglePoint");                   HiddenField hidCompleteNum = (HiddenField)Item.FindControl("hidCompleteNum");                   HiddenField hidPoint = (HiddenField)Item.FindControl("hidPoint");                   HiddenField txtScore = (HiddenField)Item.FindControl("txtScore");                   HiddenField hidid = (HiddenField)Item.FindControl("hidid");
                   decimal num=0;
                   if (txtScore.Value != "0")
                   {
                       if (hidCompleteNum.Value != "0")
                       {
                           num = (Convert.ToDecimal(hidPoint.Value) / Convert.ToDecimal(hidCompleteNum.Value) * Convert.ToDecimal(txtQuantity.Text));
                       }

                       if (num > Convert.ToDecimal(txtScore.Value))
                       {
                           num = Convert.ToDecimal(txtScore.Value);
                       }
                       txtSinglePoint.Text = Math.Floor(num).ToString() ; 
                   }
                   else
                   {
                       txtSinglePoint.Text = Math.Floor((Convert.ToDecimal(hidPoint.Value) / Convert.ToDecimal(hidCompleteNum.Value) * Convert.ToDecimal(txtQuantity.Text))).ToString();
                   }
                   
                                                                                                                  
                                      
                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                      
               }
               txtallnum2.Value = total.ToString();
           }
           else
           {
               DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Basis order by TypeName  ");
               if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
               {
                   Repeater1.DataSource = ds.Tables[0];
                   Repeater1.DataBind();
               }
               if (exists)
               {
                   DataSet ds1 = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Configuration where userID=" + u_id + " and DATEDIFF(dd, CreateTime, '" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "') = 0 order by Other3 desc");
                   int total = 0;
                   if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds1))
                   {
                       for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                       {
                           foreach (RepeaterItem Item in Repeater1.Items)
                           {
                               HiddenField hidid = (HiddenField)Item.FindControl("hidid");
                               CheckBox chk = (CheckBox)Item.FindControl("ckb");
                               TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");
                               TextBox SinglePoint = (TextBox)Item.FindControl("TextBox2");                               HiddenField hidQuantity = (HiddenField)Item.FindControl("hidQuantity");
                               if (ds1.Tables[0].Rows[i]["BasisCode"].ToString() == hidid.Value)
                               {
                                   txtQuantity.Text = ds1.Tables[0].Rows[i]["Quantity"].ToString();
                                   hidQuantity.Value = ds1.Tables[0].Rows[i]["Quantity"].ToString();
                                   SinglePoint.Text = ds1.Tables[0].Rows[i]["SinglePoint"].ToString();
                                   chk.Enabled = ZLDC.Topo.BLL.Estate.lp_Package.GetEnabled(ds1.Tables[0].Rows[i]["Reserve1"].ToString());

                                   if (ds1.Tables[0].Rows[i]["Other1"].ToString() == "1" || ds1.Tables[0].Rows[i]["Reserve1"].ToString() == "1")
                                   {
                                       chk.Checked = true;
                                       total += int.Parse(ds1.Tables[0].Rows[i]["SinglePoint"].ToString());
                                       break;
                                   }
                                   else
                                   {
                                       txtQuantity.Enabled = false;
                                   }
                               }

                           }
                       }
                   }
                   txtallnum1.Value = total.ToString();               }
               btnNone(Panel2, Panel1);
           }
       }
                            protected static void btnNone(Panel Panel2,Panel Panel1)
       {

           Panel2.Visible = false;
           Panel1.Visible = true;

       }

                            public static void BtnAdd(bool exists, DropDownList dropPK, System.Web.UI.HtmlControls.HtmlInputText txtallnum2, System.Web.UI.HtmlControls.HtmlInputText txtallnum1, string mainId, string type, System.Web.UI.HtmlControls.HtmlInputText txtTotal2, Page p, string u_id, string daytime, Repeater RpList, Repeater Repeater1,string endday,string Rrow)
       {
           if (exists)
           {
               decimal total = 0;               if (dropPK.SelectedValue == "0")
               {
                   total = Convert.ToDecimal(txtallnum1.Value);
               }
               else
               {
                   total = Convert.ToDecimal(txtallnum2.Value);
               }
               string BasisPackage = dropPK.SelectedValue;               string sql_main = " update lp_Configuration_main set ";
               sql_main += " total=" + total + " where ID=" + mainId + "";

               int i = ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql_main);
               if (dropPK.SelectedValue != "0")
               {
                   insertTableValue1(int.Parse(mainId), type,p,u_id,daytime,RpList,dropPK,Rrow);
               }
               else
               {
                   insertTableValue0(int.Parse(mainId), type, p, u_id, daytime, Repeater1, dropPK, Rrow);
               }
           }
           else
           {
               
                                                                                                                                                                                                                                                                                                                           if (endday != "0")
               {
                   DateTime startT = Convert.ToDateTime(daytime);
                   DateTime endT = Convert.ToDateTime(endday);
                   System.TimeSpan span = endT - startT;
                   for (int i = 0; i <= int.Parse(span.Days.ToString()); i++)
                   {
                       daytime = startT.AddDays(i).ToString("yyyy-MM-dd");
                       GetSql_Mail(1, txtallnum1, type, daytime, p, u_id, RpList, dropPK, Repeater1, endday, Rrow);                   }
               }
               else
               {
                   GetSql_Mail(1, txtallnum1, type, daytime, p, u_id, RpList, dropPK, Repeater1, endday, Rrow);               }
               
           }
       }

     
                                   protected static void GetSql_Mail(int j,System.Web.UI.HtmlControls.HtmlInputText txtallnum, string type, string daytime, Page p, string u_id, Repeater RpList, DropDownList dropPK, Repeater Repeater1,string endday,string Rrow)
       {

           string today = (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd"));           decimal total = Convert.ToDecimal(txtallnum.Value);           int sureScore = 0;           int isConfirm = 0;           int isComplete = 0;           int leave = 0;           int choiceType = 0;           string color = "1";           string remark = "";
           DateTime createTime = DateTime.Now;
           string createUser = _Utility.GetInfoBySession().m_sUserID;
           StringBuilder strSql_mail = new StringBuilder();
           StringBuilder strSql1 = new StringBuilder();
           StringBuilder strSql2 = new StringBuilder();

           string[] deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptExprlist(u_id);           string expr1 = deptlist[6];
           string expr2 = deptlist[7];
           string expr3 = deptlist[8];
           string expr4 = deptlist[9];
           string expr5 = deptlist[10];
           string expr6 = deptlist[11];

           if (today != null)
           {
               strSql1.Append("workDay,");
               strSql2.Append("'" + today + "',");
           }
           if (u_id != null)
           {
               strSql1.Append("userID,");
               strSql2.Append("" + u_id + ",");
           }
           strSql1.Append("deptid,");
           strSql2.Append("" + _Utility.GetInfoBySession().m_sDeptID + ",");
           strSql1.Append("total,");
           strSql2.Append("" + total + ",");
           strSql1.Append("sureScore,");
           strSql2.Append("" + sureScore + ",");
           strSql1.Append("color,");
           strSql2.Append("'" + color + "',");


           strSql1.Append("isConfirm,");
           strSql2.Append("" + isConfirm + ",");

           strSql1.Append("isComplete,");
           strSql2.Append("" + isComplete + ",");

           strSql1.Append("leave,");
           strSql2.Append("" + leave + ",");

           strSql1.Append("choiceType,");
           strSql2.Append("" + choiceType + ",");

           if (remark != null)
           {
               strSql1.Append("remark,");
               strSql2.Append("'" + remark + "',");
           }
           if (createTime != null)
           {
               strSql1.Append("createTime,");
               strSql2.Append("'" + createTime + "',");
           }
           if (createUser != null)
           {
               strSql1.Append("createUser,");
               strSql2.Append("'" + createUser + "',");
           }


           strSql1.Append("Other1,");
           strSql2.Append("'0',");
           strSql1.Append("Other2,");
           strSql2.Append("'"+ZLDC.Topo.BLL.Estate.lp_Basis.GetUserName(u_id)+"',");
           strSql1.Append("Other3,");
           strSql2.Append("'"+_Utility.GetInfoBySession().m_sDeptName+"',");
           strSql1.Append("Other4,");
           strSql2.Append("'" + expr1 + "',");
           strSql1.Append("Other5,");
           strSql2.Append("'" + expr2 + "',");
           strSql1.Append("Other6,");
           strSql2.Append("'" + expr3 + "',");
           strSql1.Append("Other7,");
           strSql2.Append("'" + expr4 + "',");
           strSql1.Append("Other8,");
           strSql2.Append("'" + expr5+ "',");
           strSql1.Append("Other9,");
           strSql2.Append("'" + expr6 + "',");
           strSql_mail.Append("insert into lp_Configuration_main(");
           strSql_mail.Append(strSql1.ToString().Remove(strSql1.Length - 1));
           strSql_mail.Append(")");
           strSql_mail.Append(" values (");
           strSql_mail.Append(strSql2.ToString().Remove(strSql2.Length - 1));
           strSql_mail.Append(")");
           strSql_mail.Append(";select @mainid=@@IDENTITY;");
                      if (type == "2")
           {
               insertTableValue0(0, type, p, u_id, daytime, Repeater1, dropPK, Rrow, strSql_mail.ToString());
           }
           else
           {
               if (j == 1)
               {
                   insertTableValue0(0, type, p, u_id, daytime, Repeater1, dropPK, Rrow, strSql_mail.ToString());
               }
               else
               {
                   insertTableValue1(0, type, p, u_id, daytime, RpList, dropPK, Rrow, strSql_mail.ToString());
               }
           }
       }

                                   protected static void UpdateOther1(int main_id)
       {
           string sql = "update lp_Configuration_main set Other1 = '0' where id="+main_id;
           ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql);
       }

                            protected static void insertTableValue1(int main_id, string type,Page p,string u_id,string daytime,Repeater RpList,DropDownList dropPK,string Rrow,string sql_main)
       {
           UpdateOther1(main_id);
           string sql = " declare @mainid int; "+sql_main+"  delete from lp_Configuration where userID = " + u_id + " and DATEDIFF(dd, CreateTime, '" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "') = 0 ";
           string[] deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptExprlist(u_id);           string expr1 = deptlist[6];
           string expr2 = deptlist[7];
           string expr3 = deptlist[8];
           string expr4 = deptlist[9];
           string expr5 = deptlist[10];
           string expr6 = deptlist[11];
           foreach (RepeaterItem Item in RpList.Items)
           {
               CheckBox chk = (CheckBox)Item.FindControl("ckb");
               HiddenField hidcode = (HiddenField)Item.FindControl("hidid");               HiddenField hidPoint = (HiddenField)Item.FindControl("hidPoint");               HiddenField hidName = (HiddenField)Item.FindControl("hidName");               HiddenField CompleteNum = (HiddenField)Item.FindControl("hidCompleteNum");                              TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");               TextBox SystemSouce = (TextBox)Item.FindControl("txtSinglePoint");               HiddenField txtScore = (HiddenField)Item.FindControl("txtScore");               HiddenField TypeName = (HiddenField)Item.FindControl("TypeName");
                                                            string BasisPackage = dropPK.SelectedValue;               decimal Systemss = Convert.ToDecimal(txtQuantity.Text) / Convert.ToDecimal(CompleteNum.Value) * Convert.ToDecimal(SystemSouce.Text);
               if (Systemss > Convert.ToDecimal(SystemSouce.Text))
               {
                   Systemss = Convert.ToDecimal(txtScore.Value);
               }
               string trfa = "0";
               string sj = "0";               if (chk.Checked||chk.Enabled==false)
               {
                   trfa = "1";
               }
               if (chk.Enabled == false)
               {
                   sj = "1";
               }
                   sql += " insert into lp_Configuration( ";
                   sql += " mainId,BasisName,BasisCode,Point,Quantity,SystemSouce,SL,BasisPackage,CreateUser,CreateTime,userID,SinglePoint,Complete,Other1,Other2,Other3";
                   sql += " ,Other4,Other5,Other6,Other7,Other8,Other9,Other10,SingleNumber,Reserve1,TF)";
                   sql += " values (";
                   sql += " @mainid,'" + hidName.Value + "','" + hidcode.Value + "'," + (hidPoint.Value == "" ? "0" : hidPoint.Value) + "," + (txtQuantity.Text == "" ? "0" : txtQuantity.Text) + "," + txtScore.Value + ",";
                   sql += " 0,'" + BasisPackage + "','" + _Utility.GetInfoBySession().m_sUserID + "','" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "'," + u_id + "," + (SystemSouce.Text == "" ? "0" : SystemSouce.Text) + ",0,'" + trfa + "','"+_Utility.GetInfoBySession().m_sDeptID+"','"+TypeName.Value+"'";
                   sql += ",'" + expr1 + "','" + expr2 + "','" + expr3 + "','" + expr4 + "','" + expr5 + "','" + expr6 + "','" + _Utility.GetInfoBySession().m_sDeptName + "'," + CompleteNum.Value + "";
                   sql += " ,'"+sj+"',1";
               sql += " );";
               
           }
           int i = ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql);
           if (type == "2")           {
               p.Response.Write("<script>parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
           }
           else
           {
               p.Response.Write("<script>alert('保存成功！');parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
           }
       }

                            protected static void insertTableValue0(int main_id, string type, Page p, string u_id, string daytime, Repeater Repeater1, DropDownList dropPK, string Rrow, string sql_main)
       {
           UpdateOther1(main_id);
           string sql = " declare @mainid int; " + sql_main + "  delete from lp_Configuration where userID = " + u_id + " and DATEDIFF(dd, CreateTime, '" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "') = 0 ";
           bool bl = false;
                                                                  string[] deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptExprlist(u_id);           string expr1 = deptlist[6];
           string expr2 = deptlist[7];
           string expr3 = deptlist[8];
           string expr4 = deptlist[9];
           string expr5 = deptlist[10];
           string expr6 = deptlist[11];
           foreach (RepeaterItem Item in Repeater1.Items)
           {

               CheckBox chk = (CheckBox)Item.FindControl("ckb");
               HiddenField hidcode = (HiddenField)Item.FindControl("hidid");               HiddenField hidPoint = (HiddenField)Item.FindControl("hidPoint");               HiddenField hidName = (HiddenField)Item.FindControl("hidName");               HiddenField hidQuantity = (HiddenField)Item.FindControl("hidQuantity");               HiddenField hidRemark = (HiddenField)Item.FindControl("hidRemark");               TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");               TextBox SystemSouce = (TextBox)Item.FindControl("TextBox2");               HiddenField txtScore = (HiddenField)Item.FindControl("txtScore");               HiddenField TypeName = (HiddenField)Item.FindControl("TypeName");
               HiddenField hidSingleNumber = (HiddenField)Item.FindControl("hidSingleNumber");                                                            string BasisPackage = dropPK.SelectedValue;
               string trfa = "0";               string sj = "0";               if (chk.Checked || chk.Enabled == false)
               {
                   trfa = "1";
               } 
               if (chk.Enabled == false)
               {
                   sj = "1";
               }
              
                   decimal Systemss=0;
                   if (hidQuantity.Value != "0" )
                   {
                       Systemss = Convert.ToDecimal(txtQuantity.Text == "" ? "0" : txtQuantity.Text) / Convert.ToDecimal(hidQuantity.Value == "" ? "0" : hidQuantity.Value) * Convert.ToDecimal(SystemSouce.Text == "" ? "0" : SystemSouce.Text);
                       if (Systemss > Convert.ToDecimal(SystemSouce.Text == "" ? "0" : SystemSouce.Text))
                       {
                           Systemss = Convert.ToDecimal(txtScore.Value == "" ? "0" : txtScore.Value);
                       }
                   }
                   bl = true;
                   sql += " insert into lp_Configuration( ";
                   sql += " mainId,BasisName,BasisCode,Point,Quantity,SystemSouce,SL,BasisPackage,CreateUser,CreateTime,userID,SinglePoint,Complete,Other1,Other2,Other3";
                   sql += " ,Other4,Other5,Other6,Other7,Other8,Other9,Other10,SingleNumber,Reserve1,TF)";
                   sql += " values (";
                   sql += "  @mainid,'" + hidName.Value + "','" + hidcode.Value + "'," + (hidPoint.Value == "" ? "0" : hidPoint.Value) + "," + (txtQuantity.Text == "" ? "0" : txtQuantity.Text) + "," + txtScore.Value + ",";
               sql += " 0,'" + BasisPackage + "','" + _Utility.GetInfoBySession().m_sUserID + "','" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "'," + u_id + "," + (SystemSouce.Text == "" ? "0" : SystemSouce.Text) + ",0,'" + trfa + "','" + _Utility.GetInfoBySession().m_sDeptID + "','"+TypeName.Value+"'";
               sql += ",'" + expr1 + "','" + expr2 + "','" + expr3 + "','" + expr4 + "','" + expr5 + "','" + expr6 + "','" + _Utility.GetInfoBySession().m_sDeptName + "'," + hidSingleNumber.Value + "";
               sql += " ,'" + sj + "',2";
               sql += " );select @@IDENTITY";
             
           }
           if (bl)
           {
               int i = ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql);
               if (type == "2")               {
                   p.Response.Write("<script>parent.popoList("+type+","+u_id+","+Rrow+");parent.ClosePop();</script>");
               }
               else
               {
                   p.Response.Write("<script>alert('保存成功！');parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
               }
           }
           else
           {
               p.Response.Write("<script>alert('请正确选择或填写完成数量！');window.parent.location.href=parent.location.href;</script>");
           }
       }

                            protected static void insertTableValue1(int main_id, string type, Page p, string u_id, string daytime, Repeater RpList, DropDownList dropPK, string Rrow)
       {
           UpdateOther1(main_id);
           string sql = "  delete from lp_Configuration where userID = " + u_id + " and DATEDIFF(dd, CreateTime, '" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "') = 0 ";
           string[] deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptExprlist(u_id);           string expr1 = deptlist[6];
           string expr2 = deptlist[7];
           string expr3 = deptlist[8];
           string expr4 = deptlist[9];
           string expr5 = deptlist[10];
           string expr6 = deptlist[11];
           foreach (RepeaterItem Item in RpList.Items)
           {
               CheckBox chk = (CheckBox)Item.FindControl("ckb");
               HiddenField hidcode = (HiddenField)Item.FindControl("hidid");               HiddenField hidPoint = (HiddenField)Item.FindControl("hidPoint");               HiddenField hidName = (HiddenField)Item.FindControl("hidName");               HiddenField CompleteNum = (HiddenField)Item.FindControl("hidCompleteNum");                              TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");               TextBox SystemSouce = (TextBox)Item.FindControl("txtSinglePoint");               HiddenField txtScore = (HiddenField)Item.FindControl("txtScore");               HiddenField TypeName = (HiddenField)Item.FindControl("TypeName");
                                                            string BasisPackage = dropPK.SelectedValue;               decimal Systemss = Convert.ToDecimal(txtQuantity.Text) / Convert.ToDecimal(CompleteNum.Value) * Convert.ToDecimal(SystemSouce.Text);
               if (Systemss > Convert.ToDecimal(SystemSouce.Text))
               {
                   Systemss = Convert.ToDecimal(txtScore.Value);
               }
               string trfa = "0";
               string sj = "0";               if (chk.Checked || chk.Enabled == false)
               {
                   trfa = "1";
               }
               if (chk.Enabled == false)
               {
                   sj = "1";
               }
               sql += " insert into lp_Configuration( ";
               sql += " mainId,BasisName,BasisCode,Point,Quantity,SystemSouce,SL,BasisPackage,CreateUser,CreateTime,userID,SinglePoint,Complete,Other1,Other2,Other3";
               sql += " ,Other4,Other5,Other6,Other7,Other8,Other9,Other10,SingleNumber,Reserve1,TF)";
               sql += " values (";
               sql += " "+main_id+",'" + hidName.Value + "','" + hidcode.Value + "'," + (hidPoint.Value == "" ? "0" : hidPoint.Value) + "," + (txtQuantity.Text == "" ? "0" : txtQuantity.Text) + "," + txtScore.Value + ",";
               sql += " 0,'" + BasisPackage + "','" + _Utility.GetInfoBySession().m_sUserID + "','" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "'," + u_id + "," + (SystemSouce.Text == "" ? "0" : SystemSouce.Text) + ",0,'" + trfa + "','" + _Utility.GetInfoBySession().m_sDeptID + "','" + TypeName.Value + "'";
               sql += ",'" + expr1 + "','" + expr2 + "','" + expr3 + "','" + expr4 + "','" + expr5 + "','" + expr6 + "','" + _Utility.GetInfoBySession().m_sDeptName + "'," + CompleteNum.Value + "";
               sql += " ,'" + sj + "',1";
               sql += " );";

           }
           int i = ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql);
           if (type == "2")           {
               p.Response.Write("<script>parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
           }
           else
           {
               p.Response.Write("<script>alert('保存成功！');parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
           }
       }

                            protected static void insertTableValue0(int main_id, string type, Page p, string u_id, string daytime, Repeater Repeater1, DropDownList dropPK, string Rrow)
       {
           UpdateOther1(main_id);
           string sql = "  delete from lp_Configuration where userID = " + u_id + " and DATEDIFF(dd, CreateTime, '" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "') = 0 ";
           bool bl = false;
                                                                  string[] deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptExprlist(u_id);           string expr1 = deptlist[6];
           string expr2 = deptlist[7];
           string expr3 = deptlist[8];
           string expr4 = deptlist[9];
           string expr5 = deptlist[10];
           string expr6 = deptlist[11];
           foreach (RepeaterItem Item in Repeater1.Items)
           {

               CheckBox chk = (CheckBox)Item.FindControl("ckb");
               HiddenField hidcode = (HiddenField)Item.FindControl("hidid");               HiddenField hidPoint = (HiddenField)Item.FindControl("hidPoint");               HiddenField hidName = (HiddenField)Item.FindControl("hidName");               HiddenField hidQuantity = (HiddenField)Item.FindControl("hidQuantity");               HiddenField hidRemark = (HiddenField)Item.FindControl("hidRemark");               TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");               TextBox SystemSouce = (TextBox)Item.FindControl("TextBox2");               HiddenField txtScore = (HiddenField)Item.FindControl("txtScore");               HiddenField TypeName = (HiddenField)Item.FindControl("TypeName");
               HiddenField hidSingleNumber = (HiddenField)Item.FindControl("hidSingleNumber");                                                            string BasisPackage = dropPK.SelectedValue;
               string trfa = "0";               string sj = "0";               if (chk.Checked || chk.Enabled == false)
               {
                   trfa = "1";
               }
               if (chk.Enabled == false)
               {
                   sj = "1";
               }

               decimal Systemss = 0;
               if (hidQuantity.Value != "0")
               {
                   Systemss = Convert.ToDecimal(txtQuantity.Text == "" ? "0" : txtQuantity.Text) / Convert.ToDecimal(hidQuantity.Value == "" ? "0" : hidQuantity.Value) * Convert.ToDecimal(SystemSouce.Text == "" ? "0" : SystemSouce.Text);
                   if (Systemss > Convert.ToDecimal(SystemSouce.Text == "" ? "0" : SystemSouce.Text))
                   {
                       Systemss = Convert.ToDecimal(txtScore.Value == "" ? "0" : txtScore.Value);
                   }
               }
               bl = true;
               sql += " insert into lp_Configuration( ";
               sql += " mainId,BasisName,BasisCode,Point,Quantity,SystemSouce,SL,BasisPackage,CreateUser,CreateTime,userID,SinglePoint,Complete,Other1,Other2,Other3";
               sql += " ,Other4,Other5,Other6,Other7,Other8,Other9,Other10,SingleNumber,Reserve1,TF)";
               sql += " values (";
               sql += " " + main_id + ",'" + hidName.Value + "','" + hidcode.Value + "'," + (hidPoint.Value == "" ? "0" : hidPoint.Value) + "," + (txtQuantity.Text == "" ? "0" : txtQuantity.Text) + "," + txtScore.Value + ",";
               sql += " 0,'" + BasisPackage + "','" + _Utility.GetInfoBySession().m_sUserID + "','" + (type == "2" ? daytime : DateTime.Now.ToString("yyyy-MM-dd")) + "'," + u_id + "," + (SystemSouce.Text == "" ? "0" : SystemSouce.Text) + ",0,'" + trfa + "','" + _Utility.GetInfoBySession().m_sDeptID + "','" + TypeName.Value + "'";
               sql += ",'" + expr1 + "','" + expr2 + "','" + expr3 + "','" + expr4 + "','" + expr5 + "','" + expr6 + "','" + _Utility.GetInfoBySession().m_sDeptName + "'," + hidSingleNumber.Value + "";
               sql += " ,'" + sj + "',2";
               sql += " );select @@IDENTITY";

           }
           if (bl)
           {
               int i = ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sql);
               if (type == "2")               {
                   p.Response.Write("<script>parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
               }
               else
               {
                   p.Response.Write("<script>alert('保存成功！');parent.popoList(" + type + "," + u_id + "," + Rrow + ");parent.ClosePop();</script>");
               }
           }
           else
           {
               p.Response.Write("<script>alert('请正确选择或填写完成数量！');window.parent.location.href=parent.location.href;</script>");
           }
       }
    
    }
}
